<div class="dao_fen">
    <div class="layui-col-md2" id="engindao">
        <div class="engindao_bac">
            <div class="engindao_div">
                <div class="engindao_title colorlan">证书分类导航</div>
                <div class="engindao_title layui-hide" style="cursor: pointer;" onclick="qie_dao('ren')" id="rendaotit">人员姓名导航</div>
                <div class="engindao_nav">
                    <a id="engindao_left"><i class="layui-icon layui-icon-left"></i></a>
                </div>
            </div>
            <!--        <div>-->
            <!--            <input type="text" id="engindao_name" placeholder="证书分类名称" class="layui-input" autocomplete="off">-->
            <!--            <button id="engindao_sea" class="laytp-btn" type="button"><i class="layui-icon layui-icon-search"></i></button>-->
            <!--        </div>-->
            <div>
                <button id="engindao_all" type="button" class="layui-btn layui-btn-sm typeall engin_dao_dian">
                    <i class="layui-icon layui-icon-home"></i>&nbsp;&nbsp;&nbsp;全部
                </button>
            </div>
            <div id="tree_content"></div>
        </div>
    </div>
    <div class="layui-col-md2 layui-hide" id="engindaomin">
        <div class="engindao_bg">
            <div class="col" id="engindao_right"><a><i class="layui-icon layui-icon-right"></i></a></div>
            <div class="engindao_title">证书分类导航</div>
        </div>
    </div>
</div>
<script>
    var daoPage = 1, daoPagesize = 20, daoFinish = false;
    layui.use(["laytp",'tree','laypage','table','dropdown','form','soulTable'], function () {
        var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown,
            form = layui.form, soulTable = layui.soulTable;

        getEnginDaoData();
        $("#engindao #engindao_left").click(function () {
            var cliHeight = document.getElementById('engindao').clientHeight;

            $("#engindao").addClass('layui-hide');
            $("#table-card #table_list").addClass('engindaomin_guan');

            document.getElementById('engindaomin').style.height = cliHeight+"px";
            $("#engindaomin").removeClass('layui-hide');
        });
        $("#engindaomin #engindao_right").click(function () {
            $("#engindao").removeClass('layui-hide');
            $("#table-card #table_list").removeClass('engindaomin_guan');
            $("#engindaomin").addClass('layui-hide');
        });

        $('#engindao #engindao_all').click(function () {
            $(this).addClass('engin_dao_dian');
            $("#engindao_content .cons .lis").removeClass('engin_dao_dian');
            $('.layui-tree-entry').each(function () {
                $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
            });
            $("#type").val(0)
            searchTableFunc(form, table);
        });

        $('#engindao #engindao_sea').click(function () {
            daoPage = 1;
            $("#engindao_content .cons").html('');
            enginDataLoading();
            getEnginDaoData()
        });


        $('.typeall').click(function () {
            $('.layui-tree-entry').each(function () {
                $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
            });
            $("#type").val('');
            searchTableFunc(form, table);
        });


        function getEnginDaoData() {
            if(daoFinish){
                return false;
            }
            var engindao_name = $("#engindao_name").val() || '';
            facade.ajax({url: ask_get_cert_type, data: {keyword: engindao_name, page:daoPage, pagesize:daoPagesize}}).done(function(res){
                if (res.code === 2000) {
                    if(res.data.current_page >= res.data.last_page){
                        enginDataFinish();
                    }


                    treeObj = tree.render({
                        elem: '#tree_content'
                        ,id: 'tree_content'
                        ,data: res.data
                        ,onlyIconControl: true
                        ,click: function(obj){
                            $("#type").val(obj.data.value);
                            searchTableFunc(form, table);

                            $('.layui-tree-entry').each(function () {
                                $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
                            });
                            $(obj.elem).find('.layui-tree-entry').eq(0).find('.layui-tree-txt').addClass('layui-tree-other');
                            $('#engindao_all').removeClass('engin_dao_dian');
                        }
                    });



                    $("#engindao_content .cons .lis").click(function () {
                        $("#engindao  #engindao_all").removeClass('engin_dao_dian');
                        $("#engindao_content .cons .lis").removeClass('engin_dao_dian');
                        $(this).addClass('engin_dao_dian');


                        var thisEnginid = parseInt($(this).attr('key')) || 0;
                        $("#enginid").val(thisEnginid)
                        searchTableFunc(form, table);
                    });


                    var height = $('.laytp-container').height() - 270 + 'px';
                    $('#tree_content').css('cssText','max-height:'+height);
                }
            });
        }



        $('#engindao #engindao_content').scroll(function (e) {
            if (isScrollBottom(this)) {
                if(!daoFinish){
                    enginDataLoading();
                    daoPage += 1;
                    getEnginDaoData();
                }
            }
        });
    })





    function isScrollBottom(obj) {
        if (obj.scrollTop + obj.clientHeight === obj.scrollHeight) {
            return true;
        } else {
            return false;
        }
    }


    function enginDataLoading() {
        daoFinish = false;
        $("#engindao #engindao_content #loading_text").html('数据加载中...');
    }
    function enginDataFinish() {
        daoFinish = true;
        $("#engindao #engindao_content #loading_text").html('数据已全部加载');
    }


</script>
